added Feb 2001 SDK
[windows-sources.git] / shared source / vb / language / shared / iconstiterator.h
blob76d0daa85bfdc702276c93c722148e63a5d83bf5
1 //-------------------------------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 //-------------------------------------------------------------------------------------------------
7 #pragma once
9 template <class T>
10 class IConstIterator
12 public:
13 virtual
14 ~IConstIterator()
18 virtual
19 bool MoveNext() = 0;
21 virtual
22 T Current() = 0;
25 template <class T>
26 class ConstIterator : public virtual IConstIterator<T>
28 public:
29 ConstIterator()
33 explicit ConstIterator(RefCountedPtr<IConstIterator<T> > spIterator)
34 : m_spIterator(spIterator)
39 template <class U>
40 ConstIterator(const U& it)
42 m_spIterator.Attach(new (zeromemory) U(it));
45 virtual __override
46 bool MoveNext()
48 if ( m_spIterator)
50 return m_spIterator->MoveNext();
52 else
54 // NULL is used to represent an empty iterator
55 return false;
59 virtual __override
60 T Current()
62 ThrowIfFalse2(m_spIterator, "Calling current on a NULL iterator");
63 return m_spIterator->Current();
66 private:
68 // Allow default copy constructor and assignment operators to
69 // be generated because RefCountedPtr is copy safe
70 RefCountedPtr<IConstIterator<T> > m_spIterator;